package edu.pku.sei.modeler.neditor.part;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.ui.views.properties.IPropertySource;

import edu.pku.sei.gefcommon.descriptor.core.PropertyDescriptorAdapter;
import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.notation.core.ShapeConstance;
import edu.pku.sei.modeler.model.notation.core.ShapeNode;

abstract public class AbstractMetaElementPart extends AbstractGraphicalEditPart implements
		PropertyChangeListener {
    public void activate() {
        super.activate();
        ((MetaModelElement) getModel()).addPropertyChangeListener(this);
    }

    public void deactivate() {
        super.deactivate();
        ((MetaModelElement) getModel()).removePropertyChangeListener(this);
    }
    public Object getAdapter(Class key) {
		if (IPropertySource.class == key) {
			Object model = getModel();
			if(model instanceof ShapeNode){
				return new PropertyDescriptorAdapter((MetaModelElement)model);
			}
		}
		return super.getAdapter(key);
	}    
/*    public DiagramEditPart getDiagramPart() {
    	return ((AbstractMetaElementPart)getParent()).getDiagramPart();
    }
*/	public void propertyChange(PropertyChangeEvent evt) {
		String type = evt.getPropertyName();
		if(type==ShapeConstance.REFRESH_ALL){
			this.refreshStructure();
			this.refreshVisuals();
		} else if(type==ShapeConstance.REFRESH_VIEW){
			this.refreshVisuals();
		}
	}
	
	public void refreshStructure(){
		this.refreshChildren();
	}

	@Override
	protected IFigure createFigure() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void createEditPolicies() {
		// TODO Auto-generated method stub
		
	}
}
